package com.github.pudding.servlet;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;

/**
 * @author Stephen
 * @since 2018/8/31
 */
public class DemoServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("get is called");


        ServletContext context = getServletContext();
        Enumeration<String> attrs = context.getInitParameterNames();
        while (attrs.hasMoreElements()) {
            System.out.println("attrs: " + attrs.nextElement());
        }

        ServletConfig servletConfig = getServletConfig();
        Enumeration<String> params = servletConfig.getInitParameterNames();

        while (params.hasMoreElements()) {
            System.out.println("params: " + params.nextElement());
        }



    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("post is called");
    }
}
